package com.hzhc.controller.wxapp;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.CntrInfo;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrInfoService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.CntrInfoVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author wuxiaoke
 * @description app箱统计模块
 * @date 2024/6/15 下午4:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/app")
public class WxApiCntrController extends BaseController {

    private final CntrInfoService cntrService;


    /**
     * 获取在场箱统计信息
     * @param cntrInfo
     * @return
     */
    @RequestMapping("/getYardCntrStatistic")
    public JSONObject getYardCntrStatistic(@RequestBody CntrInfo cntrInfo) {
        return cntrService.getYardCntrStatistic(cntrInfo);
    }

    /**
     * 箱管理 列表list
     */
    @RequestMapping("/getAppCntrList")
    @ResponseBody
    public ResultUtil<List<CntrInfoVo>> getAppCntrList(@RequestBody CntrInfoVo vo){
        Page<CntrInfoVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<CntrInfoVo> list = cntrService.getAppCntrList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }


    /**
     * 箱管理 -新增
     */
    @PostMapping("/addCntrInfo")
    @SysTemLog(operModul = "箱管理-集装箱管理",operType = "ADD",operDesc = "集装箱管理新增",modular="APP")
    public ResultUtil<T> addCntrInfo(HttpServletRequest request, @RequestBody CntrInfo vo) {
        Long userID = TokenUtil.getUserID(request);
        vo.setUserId(userID);
        vo.setAccesspath("APP端");
        return  cntrService.addCntrInfo(vo);
    }


    /**
     * 箱管理 -修改
     */
    @PostMapping("/updateCntrInfo")
    @SysTemLog(operModul = "箱管理-集装箱管理",operType = "UPDATE",operDesc = "集装箱管理修改",modular="APP")
    public ResultUtil<T> updateCntrInfo(HttpServletRequest request, @RequestBody CntrInfo vo) {
        Long userID = TokenUtil.getUserID(request);
        vo.setUserId(userID);
        vo.setAccesspath("APP端");
        return  cntrService.updateCntrInfo(vo);
    }

    /**
     * 箱管理 -删除
     */
    @PostMapping("/delCntrInfo")
    @SysTemLog(operModul = "箱管理-集装箱管理",operType = "DELETE",operDesc = "集装箱管理删除",modular="APP")
    public ResultUtil<T> delCntrInfo(HttpServletRequest request, @RequestBody CntrInfo vo){
        return cntrService.delCntrInfo(vo.getCntrNo());
    }

    /**
     * 箱号 check
     * @param request
     * @param info
     * @return
     */
    @PostMapping("/checkCntrNo")
    public ResultUtil<T> checkCntrNo(HttpServletRequest request,@RequestBody CntrInfo info){
        Boolean b = cntrService.checkCntrNo(info);
        if (b){
            return ResultUtil.ok();
        }
        return ResultUtil.build(ResultUtilCodeEnum.CNTR_NO_EXIST);
    }
}
